import {observable, extendObservable, action, toJS} from 'mobx';
import {getLogInfo} from 'util/api';
import _ from 'lodash';
import {validateFields} from '../Common.js';
import {message} from 'antd';
import store from 'store';

//导出
export default class HouseholdStore {
  constructor() {
    this.reset(true);
  }

  @action
  reset = init => {
    const state = {
      tableData: [],
      loading: false,
      // apartmentList: [],
      tableParams: {},
    };

    if (init) {
      extendObservable(this, state);
    } else {
      Object.keys(state).forEach(key => (this[key] = state[key]));
    }
  };

  @action
  onWillMount = async (location, match, history) => {
    this.reset();

    this.loading = true;
    await this.getLogInfo();
    this.loading = false;
  };
  @action
  getLogInfo = async (
    params = {
      pageNo: 1,
      pageSize: 10,
      operationType: '',
    },
  ) => {
    this.loading = true;
    const res = await getLogInfo(params);
    this.loading = false;
    if (res.result === 'success') {
      this.tableParams = {...this.tableParams, ...params};
      this.tableData = res;
    } else {
      message.error(res.msg);
    }
  };
}
